import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    rowCount: 0,
    floatCount: 23, // 微信悬浮框显示数字
  },
  getters: {
    rowCount: state => state.rowCount,
    floatCount: state => state.floatCount 
  },
  mutations: {
    setRowCount(state, count) {
      state.rowCount = count;
    },
    setFloatCount(state,count){
      state.floatCount = count;
    }

  },
  actions: {
    updateRowCount({ commit }, count) {
      commit('setRowCount', count);
    },
    upFloatCount({commit},count){
      commit('setFloatCount',count);
    }
  },
  modules: {
    addCommodity: {
      state: {
        //BasicInformation.vue
        ruleForm: {
          commodityName: '',
          commodityType: '',
          brand: '',
          productSn: '',
          commodityUnit: '',
          commodityIntro: '',
        },

        //CommodityAttributes.vue
        specForm: {
          bodyColors: [],
          storageCapacities: [],
          networkTypes: [],
          screenSizes: '',
          systems: '',
          batteryCapacities: '',
        }
      },
      mutations: {
        // 更新 ruleForm 数据
        updateRuleFormData(state, payload) {
          Object.assign(state.ruleForm, payload);
        },
    
        // 更新 specForm 数据
        updateSpecFormData(state, payload) {
          console.log('After update:', JSON.stringify(state.specForm));
          Object.assign(state.specForm, payload);
        }
      },
      actions: {
        // 更新 ruleForm 数据
        updateRuleFormData({ commit }, payload) {
          commit('updateRuleFormData', payload);
        },
    
        // 更新 specForm 数据
        updateSpecFormData({ commit }, payload) {
          commit('updateSpecFormData', payload);
        }
      }
    }
  }
})
